package com.jay.tools.adapter.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.jay.tools.adapter.IAdapterClick;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @param <T>
 */

public abstract class BaseHolderAdapter<T> extends BaseAdapter {

    protected Context mContext;
    protected List<T> mDatas;
    protected LayoutInflater mInflater;

    public IAdapterClick<T> mOnItemClick;

    public BaseHolderAdapter(Context context) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mDatas = new ArrayList<T>();
    }

    public void setData(List<T> datas) {
        mDatas = datas;
    }

    public void setOnItemClick(IAdapterClick<T> click) {
        mOnItemClick = click;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public T getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = ViewHolder.get(mContext, convertView, parent, getLayoutId(), position);
        convert(holder, getItem(position));
        return holder.getConvertView();
    }

    protected abstract void convert(ViewHolder holder, T t);

    protected abstract int getLayoutId();

}
